home *** CD-ROM | disk | FTP | other *** search
- program simpsktp;
-
- { This program demonstrates the Apiary Network Sockets Toolkit. }
- { Copyright 1994 Intelec Systems Corporation, APIary }
- { syntax: SIMPSKTP: <LocalName> <RemoteName> }
-
- { THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
- KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
- PURPOSE.
- }
-
-
- uses WinProcs, WinTypes, Objects, OWindows , Strings ,
- ODialogs, OStdDlgs, OStdWnds, OMemory , SktUnit ;
-
- {$R SIMPSKTP.RES}
-
- type
-
- { The application object }
- TSimpSktp = object(TApplication)
- procedure InitMainWindow; virtual;
- end;
-
- PMainWnd = ^TMainWnd;
- TMainWnd = object(TWindow)
- procedure SetupWindow; virtual;
- function CanClose: Boolean; virtual;
- procedure GetWindowClass( var aWndClass : TWndClass ); virtual;
- procedure Send(var Msg: TMessage);
- virtual cm_First + 1;
- procedure ExitC(var Msg: TMessage);
- virtual cm_First + 2;
- procedure SktEvent(var Msg: TMessage);
- virtual Wm_First + Wm_SktEvent;
- end;
-
- var SimpSktpApp : TSimpSktp;
- LocalName : array[ 0..16 ] of char;
- RemoteName : array[ 0..16 ] of char;
- hSocket : longint;
- SMsg : array[ 0..127 ] of char;
-
- procedure TMainWnd.ExitC(var Msg: TMessage);
- begin
- PostMessage( HWindow , WM_CLOSE , 0 , 0 );
- end;
-
- procedure TMainWnd.Send(var Msg: TMessage);
- var SndDlg : PInputDialog;
- begin
- if ( New( PInputDialog ,
- init( @Self , 'Send' ,
- 'Text to send:' ,
- sMsg , sizeof( sMsg ) ) ) )^.Execute = IDOK then
- SktWrite( hSocket , sMsg , StrLen( sMsg ) , 0 );
- end;
-
- procedure TMainWnd.SktEvent(var Msg: TMessage);
- var Evt : PSktEvent;
- Tmp : array[ 0..127 ] of char;
- begin
- Evt := PSktEvent( Msg.LParam );
- case Msg.WParam of
- SEV_READ:
- begin
- FillChar( Tmp , sizeof( Tmp ) , 0 );
- Move( Evt^.lpBuffer[0] , Tmp , Evt^.dwLength );
- MessageBox( hWindow ,
- Tmp ,
- 'Socket Event Read' ,
- MB_ICONEXCLAMATION );
- end;
- SEV_WRITE:
- begin
- MessageBox( hWindow ,
- 'Message sent!' ,
- 'Socket Event Write' ,
- MB_ICONEXCLAMATION );
- end;
- end;
- end;
-
- function TMainWnd.CanClose: Boolean;
- begin
- if hSocket <> 0 then
- SktClose( hSocket );
- CanClose := True;
- end;
-
- procedure TMainWnd.SetupWindow;
- begin
- inherited SetupWindow;
- if SktOpen( LocalName , 0 , HWindow , 128 , 1 , 1 , 0 ,
- @hSocket ) <> 0 then
- begin
- MessageBox( GetFocus , 'Could not open socket' ,
- 'Simple Socket Demo' ,
- MB_ICONSTOP );
- PostMessage( hWindow , WM_CLOSE , 0 , 0 );
- exit;
- end;
- SktSetTarget( hSocket , RemoteName , 0 , nil );
- SetMenu( hWindow , LoadMenu( hInstance , 'MAIN_MENU' ) );
- end;
-
- procedure TMainWnd.GetWindowClass( var aWndClass: TWndClass );
- begin
- inherited GetWindowClass( aWndClass );
- aWndClass.hIcon := LoadIcon( hinstance , 'ICON_1' );
- end;
-
- procedure TSimpSktp.InitMainWindow;
- begin
- MainWindow := New( PMainWnd , Init( nil ,'Simple Socket Demo' ) );
- end;
-
-
- begin
- if ParamCount < 2 then
- begin
- MessageBox( GetFocus , 'syntax:'#13'SIMPSKTP <LocalName> <RemoteName>' ,
- 'Simple Socket Demo' ,
- MB_ICONSTOP );
- end
- else
- begin
- StrPCopy( LocalName , ParamStr( 1 ) );
- StrPCopy( RemoteName , ParamStr( 2 ) );
- SimpSktpApp.Init( nil );
- SimpSktpApp.Run;
- SimpSktpApp.Done;
- end;
- end.
-